/**
 * Created by Administrator on 2018-07-03.
 * 供货商管理
 */

define(function (require,exports,module) {
    var sTpl = require("./supplierMgr.html");

    var VueComponent = Vue.extend({
        template: sTpl
        ,methods:{
            findAllSupplierMgrPo:function() {
                var $this = this;
                axios.get(basepath+"/api/inventoryManagement/findAllSupplierMgrPo"
                ).then(function (response) {
                    $this.supplierData=response.data;
                });
            },
            addSupplier:function() {
                this. addSupplierForm ={
                    companyName:'',
                    supplierAbbr:'',
                    mainContact:'',
                    phoneNumber:'',
                    email:'',
                    fax:'',
                    address:'',
                    postcode:'',
                    gender:'',
                    duty:'',
                    qqOrMsn:'',
                    url:'',
                    saleman:'',
                    remarks:''
                }
                this.$refs.supplierTable.dialogFormVisible = true;
                this.title='添加成功';
            },
            clear:function(){
                this.$refs.supplierTable.dialogFormVisible = false;
            },
            saveSupplierMgr:function () {
                var $this = this;
                this.$refs.addSupplierForm.validate(function(validate){
                    if(validate){
                        axios.post(basepath+'/api/inventoryManagement/saveSupplierPo',$this.addSupplierForm
                        )
                            .then(function (response) {
                                $this.$notify({
                                    title: $this.title,
                                    message: $this.title
                                });

                                $this.$refs.supplierTable.dialogFormVisible = false;
                             $this.checkSupplier();

                            });
                    }else{
                        $this.$notify({
                            title: '保存失败',
                            message: '保存失败'
                        });
                        return  false;
                    }
                });

            },
            editSupplier:function (scope) {
                this.$refs.supplierTable.dialogFormVisible = true;
                this. addSupplierForm=JSON.parse(JSON.stringify(scope.row));
                this.title='修改成功';
            },
            checkSupplier:function () {
                var $this = this;
                axios.get(basepath+"/api/inventoryManagement/checkSupplierMgrPo",{
                    params: {
                        companyName:$this.checkFormInline.companyName,
                        supplierAbbr:$this.checkFormInline.supplierAbbr
                    }}
                ).then(function (response) {
                    console.log(response);
                    $this.supplierData=response.data;
                });
            },
            delectSupplier:function(scope){
                var $this = this ;
                this.$confirm('确定删除？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'success'
                }).then(function() {
                    axios.post(basepath+'/api/inventoryManagement/delectSupplierMgrPo',scope.row)
                        .then(function (response) {
                            $this.$notify({
                                title: '已删除',
                                message: '已删除'
                            });

                            $this.checkSupplier();
                        });
                })

            }
        },
        mounted:function() {

        }
        ,data:function(){
            return {
                supplierData:'',
                title:'',
                radio: '',
                dialogFormVisible: false,
                checkFormInline: {
                    companyName:'',
                    supplierAbbr:''
                },
                addSupplierForm: {
                }
                ,
                pickerOptions1: {
                    shortcuts: [{
                        text: '今天',
                        onClick:function(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick:function(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick:function (picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                },
                supplierData: {}
            }
        },
        created:function (){
            this.findAllSupplierMgrPo();

            // this.urls.url = basepath+"api/appointment/findAppointment";
        },
        activated:function () {
            messages.$emit('change','供货商管理');
        }

    });
    module.exports = VueComponent;
})
